 <!--
* description: 技术援助单申请
* author: wangjuan
* createdDate: 2020-11-17
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-show-more-btn="true"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />

    <look
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData1"
      :popups-visible="editPopupsVisible1"
      :popups-state="editPopupsState1"
      :dynamic-api-style="'restful'"
      @close="close1"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import api from "@/api/subsidyManage";
import Vue from "vue";
import look from "../technicalReply/look.vue";
import { vehiclePdiPriceInquirys } from "@/api/se/vehiclePdiPriceInquiry";

export default {
  name: "ApplicationForTechnicalSupport",

  components: {
    OneTableTemplate,
    Edit: () => import("./edit"),
    look,
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.findApplyList,
      editRowData: {},
      editRowData1: {},
      selectData: {},
      editPopupsVisible: false,
      editPopupsVisible1: false,
      titleName: "区域审核",
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          size: "small",
          name: "add",
          clickEvent: () => this.add1(),
          text: this.$t("sys.button.add"),
          position: "right", // 新增
        },
        {
          compKey: "btnKey3",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "申请编号：",
                codeField: "applyCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
              },
              {
                compKey: "compKey2",
                labelName: "门店编号：",
                codeField: "dlrCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
              },
              {
                compKey: "compKey4",
                labelName: "门店名称：",
                codeField: "dlrShortName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
              },
              {
                compKey: "compKey5",
                labelName: "VIN：",
                codeField: "vin",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: true,
              },
              {
                compKey: "compKey6",
                labelName: "主题：",
                codeField: "faultTopic",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey7",
                labelName: "申请人：",
                codeField: "apply",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey8",
                labelName: "申请日期：",
                codeField: "applyStartDate,applyEndDate",
                component: () =>
                  import("@/components/org/datePicker/andtDatePicker"),
                type: "YYYY-MM-DD",
                // dataToObject: { timer: true, thirtyTime: true, hhmmss: true },
                format: "yyyy-MM-dd",
                isMust: false,
              },
              {
                compKey: "compKey9",
                labelName: "状态：",
                codeField: "status",
                component: () => import("@/components/org/commonSelect"),
                oFields: "claimStatusCode,claimStatusName",
                type: "dropdownList",
                options: [
                  { claimStatusCode: "1", claimStatusName: "提交" },
                  { claimStatusCode: "2", claimStatusName: "回复" },
                  { claimStatusCode: "3", claimStatusName: "申请关闭" },
                  { claimStatusCode: "4", claimStatusName: "关闭" },
                ],
                isMust: false,
              },
            ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "controlBtn",
                label: "操作",
                width: 100,
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "申请关闭",
                    rowFileds: "show:status-回复",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => this.hide(index),
                  },
                  {
                    compKey: "propKey2",
                    labelName: "详情",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => this.look(index),
                  },
                ],
              },
              {
                prop: "applyCode",
                label: "申请单号",
              },
              {
                prop: "carSeriesCn",
                label: "车系名称",
              },
              {
                prop: "carConfigCn",
                label: "车型名称",
              },
              {
                prop: "dlrCode",
                label: "门店编码",
              },
              {
                prop: "dlrShortName",
                label: "门店名称",
              },
              {
                prop: "applyDate",
                label: "申请日期",
              },
              {
                prop: "faultTopic",
                label: "主题",
              },
              {
                prop: "apply",
                label: "申请人",
              },
              {
                prop: "status",
                label: "状态",
              },
              {
                prop: "createDate",
                label: "创建时间",
              },
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          applyCode: "",
          dlrCode: "",
          dlrShortName: "",
          vin: "",
          faultTopic: "",
          apply: "",
          applyStartDate: "",
          applyEndDate: "",
          status: "",
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },

  mounted() {
    // 列表查询
    this.queryTable(1);

    this.$refs.multipleTable.list = [
      {
        index: 1,
      },
    ];
  },

  methods: {
    add1() {
      // this.editPopupsState = "edit";
      this.editPopupsVisible = true;
      // this.editRowData = this.$refs["multipleTable"].list[index];
    },
    look(index) {
      this.editPopupsState1 = "look1";
      this.editPopupsVisible1 = true;
      this.editRowData1 = this.$refs["multipleTable"].list[index];
    },
    // 申请关闭
    hide(index) {
      const appleyId = this.$refs["multipleTable"].list[index].appleyId;
      const that = this;
      const queryObj = {
        // 保存mutation
        type: "mutation",
        // api配置
        apiConfig: api.applicationClosed,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { appleyId: appleyId },
      };
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj);
      // 调用中台API方法（可复用）

      this.$confirm("确定申请关闭吗?", "提示", {
        type: "warning",
      }).then(() => {
        this.$requestAPI(paramD).then((response) => {
          if (response.result === "1") {
            // this.queryTable();
            this.$message("关闭成功");
          } else {
            // 作废失败
            this.$message({
              message: response.msg,
              type: "warn",
              uration: 1000,
            });
          }
          this.queryTable(1);
        });
      });
    },
    close() {
      this.editPopupsVisible = false;
      this.queryTable(1);
    },
    close1() {
      this.editPopupsVisible1 = false;
      this.queryTable(1);
    },
  },
};
</script>
